package Top_Interview_Questions.Bit_Manipulation;

import java.util.Arrays;

/**
 * @Author: 吕庆龙
 * @Date: 2020/2/2 15:15
 * <p>
 * 功能描述:
 */
public class _0268 {

    public static void main(String[] args) {
        _0268 test = new _0268();
        int[] nums = new int[]{3,0,1};
        test.missingNumber1(nums);
    }

    /**
     * 官方题解的位运算挺好的
     * https://leetcode-cn.com/problems/missing-number/solution/que-shi-shu-zi-by-leetcode/
     */
    public int missingNumber2(int[] nums) {
        int missing = nums.length;
        for (int i = 0; i < nums.length; i++) {
            missing ^= i ^ nums[i];
        }
        return missing;
    }


    /**
     * 打败30%
     */
    public int missingNumber1(int[] nums) {
        int count = 0;
        Arrays.sort(nums);
        for(int k:nums){
            if(k != count){
                break;
            }
            count++;
        }
        return count;
    }
}
